﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.PoseEditor.CCoKinDeviceNewPoseCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.JointJog;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.PoseEditor;

public class CCoKinDeviceNewPoseCmd : TxButtonCommand
{
  private Dictionary<ITxDevice, CUiKinJointJogForm> DeviceToOpenedForm { get; set; } = new Dictionary<ITxDevice, CUiKinJointJogForm>();

  private Dictionary<CUiKinJointJogForm, ITxDevice> OpenedFormToDevice { get; set; } = new Dictionary<CUiKinJointJogForm, ITxDevice>();

  public virtual string Category => PoseEditorStringTable.CMD_CATEGORY;

  public virtual string Name => PoseEditorStringTable.CMD_DEVICE_NEW_POSE_NAME;

  public virtual string Tooltip => PoseEditorStringTable.CMD_DEVICE_NEW_POSE_TOOLTIP;

  public virtual string Description => PoseEditorStringTable.CMD_DEVICE_NEW_POSE_DECRIPTION;

  public virtual string Bitmap => "PoseEditor.DeviceNewPose.bmp";

  public virtual string LargeBitmap => "PoseEditor.DeviceNewPose_LARGE.png";

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("NewPose");

  public virtual void Execute(object cmdParams)
  {
    if (!(cmdParams is ITxDevice itxDevice) || this.DeviceToOpenedForm.ContainsKey(itxDevice))
      return;
    CUiKinJointJogForm key = CApKinPoseEditorUtils.OpenPoseJointJogForm(itxDevice, new Action<object, FormClosedEventArgs>(this.FormCloseAction));
    if (key == null)
      return;
    this.DeviceToOpenedForm.Add(itxDevice, key);
    this.OpenedFormToDevice.Add(key, itxDevice);
  }

  private void FormCloseAction(object obj, FormClosedEventArgs eventArgs)
  {
    ITxDevice itxDevice;
    if (!(obj is CUiKinJointJogForm key) || !this.OpenedFormToDevice.TryGetValue(key, out itxDevice))
      return;
    if (key.CloseDialogResult == DialogResult.OK)
      CApKinPoseEditorUtils.CreateNewPose(itxDevice, key.PoseName);
    this.DeviceToOpenedForm.Remove(itxDevice);
    this.OpenedFormToDevice.Remove(key);
  }
}
